home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C# & Game Programming - A…er's Guide (2nd Edition)
/
Buono 2nd Ed.iso
/
Chapter5
/
5.57
/
5.57.cs
next >
Wrap
Text File
|
2004-09-07
|
1KB
|
42 lines
/* The keyword lock. */
using System;
using System.Threading;
namespace Chapter5 {
class MyName {
private string name;
protected MyName(string fn) {this.name = fn;}
protected string TestName(string fn) {
if (fn == "Sal") {
throw new Exception("Welcome Home!");
}
lock (this) {
if (fn != null) {
return ("nice to meet you" + this.name);
}
}
return "The End";
}
protected void YourName() {
Console.WriteLine("What is your name?");
string input = Console.ReadLine();
TestName(input);
}
static protected Thread[] test = new Thread[2];
public static void Main() {
MyName FirstName = new MyName("Salvatore");
MyName LastName = new MyName("Buono");
Thread first = new Thread(new ThreadStart(FirstName.YourName));
test[0] = first;
test[0].Start();
Thread last = new Thread(new ThreadStart(LastName.YourName));
test[1] = last;
test[1].Start();
}
}
}